package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.DisasterPreventDao;
import cn.topevery.garden.entity.po.DisasterPrevent;
import cn.topevery.garden.entity.query.DisasterPreventQuery;
import cn.topevery.garden.entity.vo.DisasterPreventVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 自然灾害防范保护
 *
 * @author code-generate
 * @date 2022-02-18
 */
@Repository
public class DisasterPreventDaoImpl extends BaseDaoImpl<DisasterPrevent> implements DisasterPreventDao {
    @Override
    public <P extends DbCsp> List<DisasterPrevent> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<DisasterPreventVO> listPage(DisasterPreventQuery query) {
        String table = "t_disaster_prevent tdp";

        String columns = "tdp.*";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tdp.c_id desc");
        sqlQueryMate
                .where(true, "tdp.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(StringUtils.isNotBlank(query.getName()), "tdp.c_db_status", ScriptConditionEnum.Eq, query.getName())
                .where(query.getType() != null, "tdp.c_db_status", ScriptConditionEnum.Eq, query.getType())
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, DisasterPreventVO.class);
    }

    @Override
    public DisasterPrevent getEntityByColumn(String key,String value){
        KeyValue<String> map=new KeyValue<>();
        map.key=key;
        map.value=value;
        return getEntityByColumnEqValue(map);
    }

    @Override
    public List<Map<String, Object>> getDisasterNameList() {
        SqlQueryMate sqlQueryMate = new SqlQueryMate("t_disaster_prevent tdp").setColumns("tdp.c_id id, tdp.c_name name");
        sqlQueryMate.where(true, "tdp.c_db_status", ScriptConditionEnum.Eq, 0);
        return getMap(sqlQueryMate);
    }
}
